import csv

headers = ['name','age','classroom']
#
# values = [
#     ('zongzhen',18,'111'),
#     ('zhihua',19,'666'),
#     ('zhicheng',20,'888'),
# ]
#
# with open('test.csv','w',newline='') as fp:
#     writer = csv.writer(fp)
#     writer.writerow(headers)
#     writer.writerows(values)

values = [
    {"name":"kangbazi","age":18,"classroom":"1901"},
    {"name":"kangbazi6","age":19,"classroom":"1902"},
    {"name":"kangbazi8","age":20,"classroom":"1903"},
]

with open('test1.csv','w',newline='') as fp:
    writer = csv.DictWriter(fp,headers)
    writer.writeheader()
    writer.writerows(values)
